<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>



    var items=[1,2,3,4,5,6];
    var results=[];

    //并行执行（setTimeout）
    function async(arg, callback) {
        console.log('参数为 ' + arg +' , 1秒后返回结果');
        setTimeout(function () { callback(arg * 2); }, 1000);
    }

    function final(value) {
        console.log('完成: ', value);
    }

    items.forEach(function(item) {
        async(item, function(result){
            results.push(result);
            if(results.length === items.length) {
                final(results[results.length - 1]);
            }
        })
    });

    //串行执行
    /*function async(arg,callback) {
        console.log("arg :",arg);
        setTimeout(function () {
            callback(arg*2);
        },1000)
    }
    //串行+递归
    function series(arg) {
        if(arg){
            async(arg,function (a) {
                results.push(a);
                return series(items.shift())
            })
        }else {
            console.log("移动完成:",results[results.length-1]);
        }
    }

    series(items.shift());*/

</script>

</body>
</html>